package com.uniandes.modelviewer

import com.uniandes.modelviewer.dsl.XmiModel

class ModelTagLib {


	def modelsList = { attrs, body ->
		def models = Model.list(sort:"name",order:"asc")
		out<< "<ul>"
		for(mdl in models)
		{
			def modelDSL = XmiModel.findWhere(name:mdl.name)			
					if(modelDSL!=null)
					{
						out<< "<li id=model."+modelDSL.id+"><a href=/GrailsModelViz/xmiModel/show/"+modelDSL.id+">"+ modelDSL.name+ "</a>"
						//out<<"<li id=model."+mdl.id+"><a href=\"#\">"+ mdl.name+ "</a>"
						//			out << "<li id=model."+modelDSL.id+"><a href=/GrailsModelViz/xmiModel/show/"+modelDSL.id+">"+ modelDSL.name+ "</a>"
						def types = mdl.classes as Class[]
						out<< "<ul>"
						for(elem in types)
						{
							out<<"<li id=class."+elem.id+"><a href=\"#\">"+ elem.name+ "</a></li>"
						}
						out<< "</ul>"
						out<< "</li>"
					}
						
				}
				out<< "</ul>"
	}

	def modelsLinks = { attrs, body ->
		def models = Model.list(sort:"name",order:"asc")
		out<< "<ul>"
		for(mdl in models)
		{
			out<<"<li id=model."+mdl.id+"><a href=\"#\">"+ mdl.name+ "</a>"
			def types = mdl.classes as Class[]
			out<< "<ul>"
			for(elem in types)
			{
				out<<"<li id=class."+elem.id+"><a href=\"#\">"+ elem.name+ "</a></li>"
			}
			out<< "</ul>"
			out<< "</li>"
		}
		out<< "</ul>"
	}

	def modelInfo = { attrs, body ->
		def models = Model.list(sort:"name",order:"asc")
		out<< "<ul>"
		for(mdl in models)
		{
			out<<"<li id=model."+mdl.id+"><a href=\"#\">"+ mdl.name+ "</a>"
			def types = mdl.classes as Class[]
			out<< "<ul>"
			for(elem in types)
			{
				out<<"<li id=class."+elem.id+"><a href=\"#\">"+ elem.name+ "</a></li>"
			}
			out<< "</ul>"
			out<< "</li>"
		}
		out<< "</ul>"
	}

}
